package controllers

import (
	"strconv"
	"yihai-go-api/models"

	beego "github.com/beego/beego/v2/server/web"
)

type BannerController struct {
	beego.Controller
}

// @Title Get
// @Description find banner by id
// @Param	id		path 	string	true		"the id you want to get"
// @Success 200 {banner} models.Banner
// @Failure 403 :id is empty
// @router /:id [get]
func (o *BannerController) Get() {

	param_id := o.Ctx.Input.Param(":id")
	id, err := strconv.Atoi(param_id)
	if err != nil {
		o.Data["json"] = err.Error()
	} else {
		ob := models.GetBannerOne(id)
		o.Data["json"] = ob
	}
	o.ServeJSON()
}

// @Title GetAll
// @Description get all objects
// @Success 200 {banner} models.Banner
// @Failure 403 :objectId is empty
// @router / [get]
func (t *BannerController) GetAll() {

	var filter map[string]string = make(map[string]string)
	filter["link"] = t.GetString("link")
	filter["status"] = t.GetString("status")
	filter["start_time"] = t.GetString("start_time")
	filter["end_time"] = t.GetString("end_time")

	banner := new(models.Banner)
	// bannerList := banner.Search(filter)
	bannerList := banner.Search2(filter)
	t.Data["json"] = bannerList
	t.ServeJSON()
}
